'''
mitmdump的演示脚本
绑定命令：mitmdump -s ./12_APP/script.py
'''

from mitmproxy import ctx

# def request(flow):
    # flow.request.headers['User-Agent'] = 'MitmProxy'
    # '''日志输出'''
    # ctx.log.info(str(flow.request.headers)) # 白色
    # ctx.log.warn(str(flow.request.headers)) # 黄色
    # ctx.log.error(str(flow.request.headers)) # 红色
    # '''请求'''
    # request = flow.request
    # info = ctx.log.info
    # info(request.url)
    # info(str(request.headers))
    # info(str(request.cookies))
    # info(request.host)
    # info(request.method)
    # info(str(request.port))
    # info(request.scheme)
    # '''中间人攻击示例,原理:赋值要访问的网站url,在手机端访问目标url时,网站内容会被替换为赋值的url网站内容'''
    # url = 'https://www.baidu.com'
    # flow.request.url = url
'''响应'''
def response(flow):
    response = flow.response
    info = ctx.log.info
    info(str(response.status_code))
    info(str(response.headers))
    info(str(response.cookies))
    info(str(response.text))
